package com.shrct.businessprocess.customerservice.impl;

import com.shrct.businessprocess.customerservice.RCRoutineServicePlan;
import com.shrct.businessprocess.customerservice.RCRoutineServicePlanCriteria;
import com.shrct.businessprocess.customerservice.RCRoutineServicePlanStatus;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import java.util.Date;
import org.hibernate.Query;

public class RCRoutineServicePlanCriteriaImpl extends HQLBasedPagedQueryCriteria<RCRoutineServicePlan> implements RCRoutineServicePlanCriteria {
  private String location;
  
  public String getLocation() {
    return this.location;
  }
  
  public RCRoutineServicePlanCriteria setLocation(final String location) {
    this.location = location;
    return this;			
    
  }
  
  private Date planDateFrom;
  
  public Date getPlanDateFrom() {
    return this.planDateFrom;
  }
  
  public RCRoutineServicePlanCriteria setPlanDateFrom(final Date planDateFrom) {
    this.planDateFrom = planDateFrom;
    return this;			
    
  }
  
  private Date planDateTo;
  
  public Date getPlanDateTo() {
    return this.planDateTo;
  }
  
  public RCRoutineServicePlanCriteria setPlanDateTo(final Date planDateTo) {
    this.planDateTo = planDateTo;
    return this;			
    
  }
  
  private RCRoutineServicePlanStatus status = RCRoutineServicePlanStatus.scheduled;
  
  public RCRoutineServicePlanStatus getStatus() {
    return this.status;
  }
  
  public RCRoutineServicePlanCriteria setStatus(final RCRoutineServicePlanStatus status) {
    this.status = status;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.customerservice.impl.RCRoutineServicePlanImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getLocation()) ){
    	hql += " and (this.location  LIKE :location)" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getPlanDateFrom()) ){
    	hql += " and ((this.planDate) >= (:planDateFrom))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getPlanDateTo()) ){
    	hql += " and ((this.planDate) <= (:planDateTo))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStatus()) ){
    	hql += " and ((this.status) = (:status))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    addOrder("this.planDate",edu.fudan.mylang.pf.query.OrderItem.DESC);
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getLocation())){
    	query.setParameter("location",getLocation()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getPlanDateFrom())){
    	query.setParameter("planDateFrom",getPlanDateFrom()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getPlanDateTo())){
    	query.setParameter("planDateTo",getPlanDateTo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStatus())){
    	query.setParameter("status",getStatus()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public RCRoutineServicePlanCriteriaImpl() {
    initOrderBys();
  }
}
